package com.lancoo.znbkxx.teacher.utils

import android.content.Context
import android.util.Log
import android.view.View
import androidx.viewpager.widget.ViewPager
import androidx.viewpager2.widget.ViewPager2

/**
 * Created by wealive on 2021/3/12.
 *
 *
 */
class CardTransformer(val context: Context) : ViewPager.PageTransformer {
    private val mOffset = DensityUtils.dp2px(context, 8f)
    override fun transformPage(page: View, position: Float) {
        page.apply {
            val scaleFactor = (height - mOffset * position) / page.height
            when {
                position < -1 -> {
                    alpha = 0f
                    scaleX = scaleFactor
                    scaleY = scaleFactor
                }
                position <= 0 -> {
                    alpha = 1f + position
                    translationY = 0f
                    translationZ = 1f
                    scaleX = scaleFactor
                    scaleY = scaleFactor
                }
                position < 1 -> {
                    alpha = 1.6f - position
                    translationX = -position * page.width
                    translationY = mOffset * position
                    translationZ = 1f
                    scaleX = scaleFactor
                    scaleY = scaleFactor
                }
                else -> {
                    alpha = 1f - 0.4f * position
                    translationX = -position * page.width
                    translationY = mOffset * position
                    translationZ = -position
                    scaleX = scaleFactor
                    scaleY = scaleFactor
                }
            }
        }
    }
}